/**
 * C（控制器）就是 M（模型）和 V（视图）的中介者
 */

class AbstractView{
    rander(data){
        throw new Error("rander")
    }
}

class AbstractControler{
    update(data){
        throw new Error("update")
    }
}

class BannerView extends AbstractView{
    rander(data){
        console.log("banner渲染",data)
    }
}

class ListView extends AbstractView{
    rander(data){
        console.log("ListView渲染",data)
    }
}

const TypeEnum={
    BANNER :"banner",
    LIST:"list"
}
class Controler extends AbstractControler{
    listView = null
    bannerView =null
    registerListView(view){
        this.listView = view
    }
    registerBannerView(view){
        this.bannerView = view
    }
    update(data){
        if(data.type = TypeEnum.BANNER){
            this.bannerView.rander(data)
        }else if (data.type == TypeEnum.LIST){
            this.listView.rander(data)
        }
    }
}
class Model {
    constructor(type,text){
        this.type = type
        this.text = text
    }
}






const controler = new Controler()
controler.registerBannerView(new BannerView())
controler.registerListView(new ListView())
controler.update(new Model(TypeEnum.BANNER,"数据"))